/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Abastecimiento;

import commonsbeans.*;
import entities.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import persistence.*;

/**
 *
 * @author Felipe Corredor
 */
@ManagedBean
@ViewScoped
public class ConsultaHistoricoCompras implements Serializable {

    @ManagedProperty(value = "#{sessionBean}")
    private SessionBean sessionBean;
    @ManagedProperty(value = "#{applicationBean}")
    private ApplicationBean applicationBean;
    private HistoricoCompraJpaController historicoCompraJpaController = null;
    public List<HistoricoCompra> listaHistorico = new ArrayList<HistoricoCompra>();

    public ConsultaHistoricoCompras() {
    }

    //Constructor 
    @PostConstruct
    public void init() {
        if (sessionBean.getUsuarioActual() != null) {
            initControllers();
            cargarResumenHistorico();
        }

    }

    //<editor-fold defaultstate="collapsed" desc="Funcionalidad">
    /**
     * Metodo para cargar el resumen del historico de compras
     *
     */
    private void cargarResumenHistorico() {
        listaHistorico = sessionBean.getUsuarioActual().getCiudadIdCiudad().getHistoricoCompraList();
    }
    public void cargarResumenActualizar(){
     listaHistorico.clear();
     listaHistorico= historicoCompraJpaController.getHistoricoCiudad(sessionBean.getUsuarioActual().getCiudadIdCiudad());
    }
//</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Getter's y setter's">
    public ApplicationBean getApplicationBean() {
        return applicationBean;
    }

    public void setApplicationBean(ApplicationBean applicationBean) {
        this.applicationBean = applicationBean;
    }

    public List<HistoricoCompra> getListaHistorico() {
        return listaHistorico;
    }

    public void setListaHistorico(List<HistoricoCompra> listaHistorico) {
        this.listaHistorico = listaHistorico;
    }

    public SessionBean getSessionBean() {
        return sessionBean;
    }

    public void setSessionBean(SessionBean sessionBean) {
        this.sessionBean = sessionBean;
    }

    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Inicializar controladores">
    public void initControllers() {
        FacesContext context = FacesContext.getCurrentInstance();
        historicoCompraJpaController = (HistoricoCompraJpaController) context.getELContext().getELResolver().getValue(context.getELContext(), null, "historicoCompraJpaController");


    }
//</editor-fold>
}
